if(time==1 && stagephase==1){ FadeOutMusic(MUmain,60); }

if(time==100 && stagephase==1){ CreateEnemyFromFile("script\Functions\stagebars.txt",0,0,0,0,6); }

if(time==500 && stagephase==1){ phase+=1; frame=0; enemyx=0; enemyy=0; enemiescalled=0; }

if(nextphase==1 && stagephase==1){ phase+=1; frame=0; enemyx=0; enemyy=0; enemiescalled=0; nextphase=0; SetCommonData("IncreasePhase",0); }

if(phase==1 && stagephase==1){
	if(enemiescalled==0){ SetCommonData("PlayMusic",1); newviewx=-10; newviewy=-15; viewmovetimexy=240; }
	if(frame%20==0){
		if(enemiescalled<6){ CreateEnemyFromFile("script\Enemies\Stage 6\601.txt",cx-100+enemyx,miny-32,0,0,1); }
		if(enemiescalled==9){ enemyx=0; }
		if(enemiescalled>=9 && enemiescalled<15){ CreateEnemyFromFile("script\Enemies\Stage 6\601.txt",cx+100-enemyx,miny-32,0,0,2); }
	enemiescalled++; enemyx+=200/5; }
	if(enemiescalled>=20){ nextphase=1; }
}
if(phase==2 && stagephase==1){
	if(enemiescalled==0){ newviewx=0; newviewy=10; viewmovetimexy=240; }
	if(enemiescalled==20){ newviewx=0; newviewy=-10; viewmovetimexy=240; }
	if(frame%15==0){
if(enemiescalled<12 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Stage 6\602.txt",maxx+32,miny+50+enemyy,0,0,1); }
if(enemiescalled<12 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Stage 6\602.txt",minx-32,miny+50+enemyy,0,0,1); }
if(enemiescalled==14){ enemyy=0; }
if(enemiescalled>=14 && enemiescalled<28 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Stage 6\602.txt",maxx+32,miny+50+enemyy,0,0,2); }
if(enemiescalled>=14 && enemiescalled<28 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Stage 6\602.txt",minx-32,miny+50+enemyy,0,0,2); }
	enemiescalled++; enemyy+=20; }
	if(enemiescalled>=34){ nextphase=1; }
}
if(phase==3 && stagephase==1){
	if(frame%20==0){
if(enemiescalled%4==0 && enemiescalled%8==0 && enemiescalled<36){ CreateEnemyFromFile("script\Enemies\Stage 6\602.txt",minx-32,miny+150,0,0,1); }
if(enemiescalled%4==0 && enemiescalled%8!=0 && enemiescalled<36){ CreateEnemyFromFile("script\Enemies\Stage 6\602.txt",maxx+32,miny+150,0,0,1); }

if(enemiescalled>=0 && enemiescalled<6){ CreateEnemyFromFile("script\Enemies\Stage 6\601.txt",cx+100-enemyx,miny-32,0,0,1); }
if(enemiescalled==9){ enemyx=0; }
if(enemiescalled>=9 && enemiescalled<15){ CreateEnemyFromFile("script\Enemies\Stage 6\601.txt",cx-100+enemyx,miny-32,0,0,1); }
if(enemiescalled==18){ enemyx=0; }
if(enemiescalled>=18 && enemiescalled<24){ CreateEnemyFromFile("script\Enemies\Stage 6\601.txt",cx+100-enemyx,miny-32,0,0,1); }
if(enemiescalled==27){ enemyx=0; }
if(enemiescalled>=27 && enemiescalled<33){ CreateEnemyFromFile("script\Enemies\Stage 6\601.txt",cx-100+enemyx,miny-32,0,0,1); }
	enemiescalled++; enemyx+=200/5; }
	if(enemiescalled>=40){ nextphase=1; }
}
if(phase==4 && stagephase==1){
	if(enemiescalled==0){ newviewx=0; newviewy=-10; viewmovetimexy=120; }
	if(frame%20==0){
if(enemiescalled<15){ CreateEnemyFromFile("script\Enemies\Stage 6\601.txt",cx+rand(-100,100),miny-32,0,0,2); }
	enemiescalled++; }
	if(enemiescalled>=24){ nextphase=1; }
}
if(phase==5 && stagephase==1){
	if(enemiescalled==0){ newviewx=0; newviewy=-20; viewmovetimexy=60; }
	if(frame%12==0){
	if(enemiescalled<20 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Stage 6\602.txt",minx-32,miny+50+enemyy,0,0,1); }
	if(enemiescalled<20 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Stage 6\602.txt",maxx+32,miny+50+enemyy,0,0,2); }
	enemiescalled++; enemyy+=8; }
	if(enemiescalled>=24){ nextphase=1; }
}
if(phase==6 && stagephase==1){
	if(enemiescalled==0){ newviewx=-15; newviewy=-20; viewmovetimexy=120; }
	if(frame%20==0){
if(enemiescalled<15){ CreateEnemyFromFile("script\Enemies\Stage 6\601.txt",cx+rand(-100,100),miny-32,0,0,1); }
if(enemiescalled<16 && enemiescalled%2==0){ CreateEnemyFromFile("script\Enemies\Stage 6\602.txt",maxx+32,miny+50+enemyy,0,0,2); }
if(enemiescalled<16 && enemiescalled%2!=0){ CreateEnemyFromFile("script\Enemies\Stage 6\602.txt",minx-32,miny+50+enemyy,0,0,2); }
	enemiescalled++; enemyy+=16; }
	if(enemiescalled>=24){ nextphase=1; }
}
if(phase==7 && stagephase==1){
	if(enemiescalled==0){ newviewx=20; newviewy=0; viewmovetimexy=90; }
	if(enemiescalled==8){ newviewx=-20; newviewy=0; viewmovetimexy=90; }
	if(frame%15==0){
		if(enemiescalled<10){ CreateEnemyFromFile("script\Enemies\Stage 6\606.txt",maxx+32,miny+rand(70,90),0,0,1); }
		if(enemiescalled>=8 && enemiescalled<18){ CreateEnemyFromFile("script\Enemies\Stage 6\606.txt",minx-32,miny+rand(70,90),0,0,1); }
	enemiescalled++; }
	if(enemiescalled>=24){ nextphase=1; }
}
if(phase==8 && stagephase==1){
	if(enemiescalled==0){ newviewx=0; newviewy=0; viewmovetimexy=90; }
	if(frame%15==0){
		if(enemiescalled<20){
			CreateEnemyFromFile("script\Enemies\Stage 6\606.txt",maxx+32,miny+rand(70,90),0,0,1);
			CreateEnemyFromFile("script\Enemies\Stage 6\606.txt",minx-32,miny+rand(70,90),0,0,1);
		}
		if((enemiescalled+0)%6==0 && enemiescalled<18){
			CreateEnemyFromFile("script\Enemies\Stage 6\602.txt",maxx+32,miny+100,0,0,1);
			CreateEnemyFromFile("script\Enemies\Stage 6\602.txt",minx-32,miny+100,0,0,1);
		}
		if((enemiescalled+3)%6==0 && enemiescalled<18){
			CreateEnemyFromFile("script\Enemies\Stage 6\602.txt",maxx+32,miny+50,0,0,2);
			CreateEnemyFromFile("script\Enemies\Stage 6\602.txt",minx-32,miny+50,0,0,2);
		}
	enemiescalled++; }
	if(enemiescalled>=28){ nextphase=1; }
}
if(phase==9 && stagephase==1){
	if(enemiescalled==0){ newviewx=0; newviewy=-20; viewmovetimexy=60; }
	if(enemiescalled==7){ newviewx=0; newviewy=0; viewmovetimexy=300; }
	if(frame%10==0){
		if(enemiescalled<24){
			CreateEnemyFromFile("script\Enemies\Stage 6\606.txt",maxx+32,miny+rand(70,90),0,0,1);
			CreateEnemyFromFile("script\Enemies\Stage 6\606.txt",minx-32,miny+rand(70,90),0,0,1);
		}
	enemiescalled++; }
	if(enemiescalled>=40){ nextphase=1; }
}
if(phase==10 && stagephase==1){
	if(enemiescalled==0){ newviewx=45; newviewy=-10; viewmovetimexy=300; }
	if(enemiescalled==7){ newviewx=45; newviewy=0; viewmovetimexy=300; }
	if(enemiescalled==15){ newviewx=30; newviewy=-10; viewmovetimexy=300; }
	if(frame%48==0){
if(enemiescalled==0){ CreateEnemyFromFile("script\Enemies\Stage 6\603.txt",cx+rand(-40,40),miny+rand(70,100),0,0,[0,1]); }
if(enemiescalled==5){ CreateEnemyFromFile("script\Enemies\Stage 6\603.txt",cx+rand(-90,-120),miny+rand(70,100),0,0,[0,1]); }
if(enemiescalled==7){ CreateEnemyFromFile("script\Enemies\Stage 6\603.txt",cx+rand(90,120),miny+rand(70,100),0,0,[0,1]); }
if(enemiescalled==12){ CreateEnemyFromFile("script\Enemies\Stage 6\603.txt",cx+rand(100,140),miny+rand(70,100),0,0,[30,1]); }
if(enemiescalled==13){ CreateEnemyFromFile("script\Enemies\Stage 6\603.txt",cx+rand(30,70),miny+rand(90,120),0,0,[30,1]); }
if(enemiescalled==14){ CreateEnemyFromFile("script\Enemies\Stage 6\603.txt",cx+rand(-70,-30),miny+rand(110,140),0,0,[30,1]); }
if(enemiescalled==15){ CreateEnemyFromFile("script\Enemies\Stage 6\603.txt",cx+rand(-140,-100),miny+rand(130,160),0,0,[30,1]); }
	enemiescalled++; }
	if(enemiescalled>=20){ nextphase=1; }
}
if(phase==11 && stagephase==1){
	if(enemiescalled==7){ newviewx=50; newviewy=0; viewmovetimexy=300; }
	if(frame%48==0){
		if(enemiescalled==0){
		CreateEnemyFromFile("script\Enemies\Stage 6\603.txt",cx+rand(100,140),miny+rand(70,100),0,0,[0,2]);
		CreateEnemyFromFile("script\Enemies\Stage 6\603.txt",cx+rand(-140,-100),miny+rand(70,100),0,0,[0,2]);
		}
		if(enemiescalled==3){
		CreateEnemyFromFile("script\Enemies\Stage 6\603.txt",cx+rand(-30,30),miny+rand(70,100),0,0,[0,2]);
		}
		if(enemiescalled==8){
		CreateEnemyFromFile("script\Enemies\Stage 6\603.txt",cx+rand(100,140),miny+rand(70,100),0,0,[30,2]);
		CreateEnemyFromFile("script\Enemies\Stage 6\603.txt",cx+rand(-140,-100),miny+rand(70,100),0,0,[30,2]);
		}
		if(enemiescalled==11){
		CreateEnemyFromFile("script\Enemies\Stage 6\603.txt",cx+rand(-30,30),miny+rand(70,100),0,0,[30,2]);
		}
		if(enemiescalled==14){
		CreateEnemyFromFile("script\Enemies\Stage 6\603.txt",cx+rand(50,70),miny+rand(70,100),0,0,[30,2]);
		CreateEnemyFromFile("script\Enemies\Stage 6\603.txt",cx+rand(-70,-50),miny+rand(70,100),0,0,[30,2]);
		}
	enemiescalled++; }
	if(enemiescalled>=19){ nextphase=1; }
}
if(phase==12 && stagephase==1){
	if(enemiescalled==0){ newviewx=25; newviewy=-10; viewmovetimexy=300; }
	if(enemiescalled==10){ newviewx=25; newviewy=0; viewmovetimexy=300; }
	if(frame%48==0){
if(enemiescalled==0){ CreateEnemyFromFile("script\Enemies\Stage 6\603.txt",cx+rand(-40,40),miny+rand(70,100),0,0,[0,3]); }
if(enemiescalled==5){ CreateEnemyFromFile("script\Enemies\Stage 6\603.txt",cx+rand(90,120),miny+rand(70,100),0,0,[0,3]); }
if(enemiescalled==7){ CreateEnemyFromFile("script\Enemies\Stage 6\603.txt",cx+rand(-90,-120),miny+rand(70,100),0,0,[0,3]); }
if(enemiescalled==12){ CreateEnemyFromFile("script\Enemies\Stage 6\603.txt",cx+rand(-100,-140),miny+rand(70,100),0,0,[0,3]); }
if(enemiescalled==13){ CreateEnemyFromFile("script\Enemies\Stage 6\603.txt",cx+rand(-30,-70),miny+rand(90,120),0,0,[0,3]); }
if(enemiescalled==14){ CreateEnemyFromFile("script\Enemies\Stage 6\603.txt",cx+rand(70,30),miny+rand(110,140),0,0,[0,3]); }
if(enemiescalled==15){ CreateEnemyFromFile("script\Enemies\Stage 6\603.txt",cx+rand(140,100),miny+rand(130,160),0,0,[0,3]); }
	enemiescalled++; }
	if(enemiescalled>=22){ nextphase=1; }
}
if(phase==13 && stagephase==1){
	if(enemiescalled==0){ newviewx=0; newviewy=0; viewmovetimexy=600; }
	if(frame%60==0){
		if(enemiescalled==0){
		CreateEnemyFromFile("script\Enemies\Stage 6\603.txt",cx+rand(120,140),miny+rand(70,100),0,0,[0,3]);
		CreateEnemyFromFile("script\Enemies\Stage 6\603.txt",cx+rand(-120,-140),miny+rand(70,100),0,0,[0,3]);
		}
		if(enemiescalled==2){
		CreateEnemyFromFile("script\Enemies\Stage 6\603.txt",cx+rand(-30,30),miny+rand(70,100),0,0,[30,2]);
		}
		if(enemiescalled==4){
		CreateEnemyFromFile("script\Enemies\Stage 6\603.txt",cx+rand(120,140),miny+rand(70,100),0,0,[30,1]);
		CreateEnemyFromFile("script\Enemies\Stage 6\603.txt",cx+rand(-120,-140),miny+rand(70,100),0,0,[30,1]);
		}
	enemiescalled++; enemyx+=90; }
	if(enemiescalled>=11){ nextphase=1; }
}
if(phase==14 && stagephase==1){
	if(frame>=30 && frame<120){ doorangle+=1*cos(doorangle*1.5); }
	if(enemiescalled==3){ newviewx=-90; newviewy=0; viewmovetimexy=150; }
	if(enemiescalled==5){ CreateEnemyFromFile("script\Functions\fadeout-in.txt",0,0,0,0,0); }
	if(enemiescalled==6){
		newviewx=0; newviewy=0; viewmovetimexy=2;
		bgphase=2; scroll=0;
	}
	if(enemiescalled==7){ SetCommonData("BackgroundStop",1); }
	if(enemiescalled==8){ nextphase=1; }
	if(frame%55==0){ enemiescalled++; }
}